#include<cstdio>
int n;
char map[5][5];
int p[5]={0,2,16,512,65535};
int temp[5][5];
void change(int x);
{
    int i=1,j=1;
    int t,count=0;
    while(count<n*n)
    {
       t=x%2;
       x=x/2;
       temp[i][j]=t;
       j++;
       if(j==n+1){j=1;i++}	 
       count++;
    }
}
int main()
{
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    scanf("%d",&n);
    while(n!=0)
    {
 	for(int i=1;i<=n;i++)
	    for(int j=1;j<=n;j++)
	        scanf("%c",&map[i][j]);
	for(int i=0;i<p[n];i++)
	{	
 	    change(i);
	    if(!judge())continue;
	}

